
$(function(){
	new Vue({
		el:"#shopGoodSecondeTypeApp",
		data:{
			fullscreenLoading:false,
			activeName: 'first',
			title:"新增一级分类",
			formLabelWidth:"120px",
			shopGoodPlatformData:[],
			categoryId:"",
			dialogEditFormVisible:false,
		    uploadUrl: "http://39.100.131.147:8888/goods/address/uploadFile",
		    carouseImgUrl:[],
		    form:{
		    	name:"",
		        showOrder:0,
		    },
		    editFrom:{
		    	name:"",
		    },
			
		},
		created:function(){
			parent.vueData.$data.hreHtml="../goodSecondType/index.html";
			parent.vueData.activeIndex  = "6";
			parent.vueData.getLeftNav("6")
			parent.vueData.$data.categoryIndex = 2
			this.categoryId = localStorage.getItem("goodCategoryId");
			localStorage.removeItem("goodCategoryId")
			this.getSecondList()
		},
		methods:{
			getSecondList(){
               this.fullscreenLoading = true;
               axios({
               	url: POSTURL.selectByParentCategoryId,
               	method: 'post',
               	data: {
					uid:this.categoryId
				},
               }).then(response => {
               	this.fullscreenLoading = false;
               	if (response.data.code === 100) {
					this.shopGoodPlatformData = response.data.result
               	} else {
               		this.$message.error(response.data.message);
               	}
               }).catch(error => {
               	this.fullscreenLoading = false;
               	console.log(error);
               	this.$message.error('服务器出错!');
               })
			},
			handleClick(tab, event) {
				console.log(tab.name);
			},
			handleEdit(val){
				this.dialogEditFormVisible = true;
				this.carouseImgUrl= [];
				this.carouseImgUrl.push({
					name: "分类图片",
				    url: val.photo,
				})
				this.editFrom.name = val.name
				this.editFrom.categoryId = val.uid
			},
			configEditUpload(){
				if(stringEmpty(this.editFrom.name)){
					this.$message.error("分类名称不能为空");
					return;
				}
				if(this.carouseImgUrl.length<=0){
					this.$message.error("分类图片不能为空");
					return;
				}
				this.editFrom.photo  = this.carouseImgUrl[0].url
				axios({
					url: POSTURL.editGoodType,
					method: 'post',
					data: this.editFrom
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.$message({
							showClose: true,
							message: response.data.message,
							type: 'success'
						});
						this.dialogEditFormVisible = false;
						this.getSecondList()
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
				
			},
			beforeCourseRemove(file, fileList) {
				  let index = this.carouseImgUrl.findIndex( fileItem => {
				       return fileItem.url === file.url
				   })
				  this.carouseImgUrl.splice(index, 1)
				return true;
			},
			handleCoverExceed(files, fileList) {
				this.$message.warning("分类图片只能上传一张图片")
			},
			handleCoverSuccess(response, file, fileList) {
				if (response.code == 100) {
					this.carouseImgUrl.push({
						name: "分类图片",
			            url: response.result,
					})
					
				}
			},
			handleDelete(val){
				this.fullscreenLoading = true;
				let param = {
					categoryId: val.uid,
				}
				axios({
					url: POSTURL.deleteCategory,
					method: 'post',
					data: param
				}).then(response => {
					this.fullscreenLoading = false;
					if (response.data.code === 100) {
						this.$message({
							showClose: true,
							message: response.data.message,
							type: 'success'
						});
						this.getSecondList()
					} else {
						this.$message.error(response.data.message);
					}
				}).catch(error => {
					this.fullscreenLoading = false;
					console.log(error);
					this.$message.error('服务器出错!');
				})
			}
		}
	})
})